from django.db import models
from django.contrib.auth import get_user_model

from apps.users.models import BaseModel
from apps.courses.models import Course

# from apps.organizations.models import Teacher

UserProfile = get_user_model()
# 收藏类型选项
FAV_TYPE = (
    (1, "课程"),
    (2, "机构"),
    (3, "讲师"),
)


# 用户咨询表
class UserAsk(BaseModel):
    # 姓名
    name = models.CharField(verbose_name="姓名", max_length=20)
    # 手机
    phone = models.CharField(verbose_name="手机", max_length=11)
    # 课程名
    course_name = models.CharField(verbose_name=u"课程名", max_length=50)

    # 配置信息
    class Meta:
        verbose_name = "用户咨询"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{name}_{course_name}({phone})".format(name=self.name, course_name=self.course_name, phone=self.phone)


# 用户评论表
class CourseComments(BaseModel):
    # 用户
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    # 课程
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)
    # 评论内容
    comments = models.CharField(verbose_name="评论内容", max_length=300)

    # 配置信息
    class Meta:
        verbose_name = "用户评论"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.comments


# 用户收藏表
class UserFavorites(BaseModel):
    # 用户
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    # 收藏ID
    fav_id = models.IntegerField(verbose_name="收藏ID")
    # 收藏类型
    fav_type = models.IntegerField(verbose_name="收藏类型", choices=FAV_TYPE, default=1)

    # 配置信息
    class Meta:
        verbose_name = "用户收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{user}_{id}".format(user=self.user.username, id=self.fav_id)


# 用户消息表
class UserMessage(BaseModel):
    # 用户
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    # 消息
    message = models.CharField(verbose_name="消息内容", max_length=200)
    # 消息状态
    has_read = models.BooleanField(verbose_name=u"消息状态", default=False)

    # 配置信息
    class Meta:
        verbose_name = "用户消息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.message


# 用户课程表
class UserCourse(BaseModel):
    # 用户
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.CASCADE)
    # 课程
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.CASCADE)

    # 配置信息
    class Meta:
        verbose_name = "用户课程"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.course.name
